import django
import os

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'wealth_backend.settings')
django.setup()

from users.models import User
from rest_framework.authtoken.models import Token

# 创建测试用户
user, created = User.objects.get_or_create(
    username='testuser',
    defaults={'email': 'test@example.com'}
)

if created:
    user.set_password('testpass123')
    user.save()
    print('创建新用户:', user.username)
else:
    print('用户已存在:', user.username)

# 创建或获取token
token, token_created = Token.objects.get_or_create(user=user)
print('Token:', token.key)